<template>
	<view class="personalCenter" :style="{borderTopWidth:statusBarHeight}">
		<view class="personal-center-header">
			<view class="user-info">
				<view class="avatar" @click="getUserProfile" v-if="userInfoVo.avatarUrl==null||userInfoVo.avatarUrl==''"><image src="../../static/img/temp/avatar.jpg" ></image></view>
				<view class="avatar" @click="getUserProfile" v-else><image :src="baseUrl+userInfoVo.avatarUrl" ></image></view>
				<view class="content">
					<view class="name">{{userInfoVo.nickName}}</view>
					<view class="remarks" @click="getUserProfile" v-if="userInfoVo.avatarUrl==null||userInfoVo.avatarUrl==''">点击更新头像</view>
				</view>
			</view>
		</view>
		<view class="jump">
			<view class="jump-title">我的订单</view>
			<view class="jump-item" @click="toInspectionRecord"><image src="/static/img/icon_Record.png" class="icon"></image>检查记录</view>
		</view>
		<!-- 底部导航s -->
		<view class="menu-bar">
			<view class="menu-bar-item" @click="toHome"><view class="icon icon-home"></view><text>首页</text></view>
			<view class="menu-bar-item selected" @click="toPersonalCenter"><view class="icon icon-me"></view><text>我的</text></view>
		</view>
		<!-- 底部导航s -->
	</view>
</template>

<script>
	import config from '@/common/config'
	// 引入配置
	import {
	getUserInfo
	} from '@/common/api.js';
	var statusBarHeight = uni.getSystemInfoSync().statusBarHeight + 'px'
	import { loginWeixin,saveWeixinNickName} from '@/common/api.js';
	let that=this;
	export default {
		data() {
			return {
				statusBarHeight: statusBarHeight,
				userInfoVo:null,
				baseUrl:null
			}
		},onLoad() {
			that=this;
			this.baseUrl=config.baseUrl;
		},onShow() {
			this.getUserInfo();
		
		},
		methods: {
			getUserInfo(){
				let req={};
				getUserInfo(req).then(data => {
					this.userInfoVo=data;
					console.log(data)
				
				}).catch(() => {
				
				})
			},
			toInspectionRecord() {
				uni.redirectTo({
					url: '../inspectionRecord/inspectionRecord',
				});
			},
			toHome() {
				uni.redirectTo({
					url: '../index/index',
				});
			},
			toPersonalCenter() {
				uni.redirectTo({
					url: '../personalCenter/personalCenter',
				});
			},getUserProfile(e) {
    // 推荐使用wx.getUserProfile获取用户信息，开发者每次通过该接口获取用户个人信息均需用户确认
    // 开发者妥善保管用户快速填写的头像昵称，避免重复弹窗
    uni.getUserProfile({
      desc: '用于完善会员资料', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
      success: (res) => {
		  console.log( res.userInfo)
    let req = res.userInfo;
	saveWeixinNickName(req).then(data => {
		//this.userInfoVo=data;
		console.log(data)
	that.userInfoVo.avatarUrl=data.avatarUrl;
	that.userInfoVo.nickName=data.nickName;
	}).catch(() => {
	
	})

      }
    })
  }
		}
	}
</script>

<style>
	page{background-color: #fff;}
</style>